package com.edgclub.edg.api;

import android.content.Context;

//import com.guzhichat.guzhi.api.param.posts.GameParam;
//import com.guzhichat.guzhi.http.AsyncHttpClient;
//import com.guzhichat.guzhi.http.VolleyListener;

import com.edgclub.edg.api.param.GameParam;
import com.edgclub.edg.http.VolleyListener;
import com.edgclub.edg.http.async.AsyncHttpClient;

import java.util.ArrayList;

/**
 * 游戏操作的api
 * 
 *
 */
public class GameApi extends GuZhiApi {
	
	// 用来管理所有的请求的线程
	private ArrayList<String> tags = new ArrayList<String>();

	private AsyncHttpClient asyncHttpClient;

	public GameApi(Context mContext) {
		super(mContext);
		asyncHttpClient = new AsyncHttpClient();
	}
	
	/**
	 * 游戏列表
	 * 
	 * @param params
	 * @param listener
	 */
	public void getGameList(GameParam params, VolleyListener listener) {
		post(ApiConfig.APIURL.URL_GAME_LIST,
				ApiConfig.APIURL.URL_GAME_LIST, params, listener);
		tags.add(ApiConfig.APIURL.URL_GAME_LIST);
	}
	/**
	 * 游戏banner
	 * 
	 * @param params
	 * @param listener
	 */
	public void getGameBanner(GameParam params, VolleyListener listener) {
		post(ApiConfig.APIURL.URL_GAME_BANNER,
				ApiConfig.APIURL.URL_GAME_BANNER, params, listener);
		tags.add(ApiConfig.APIURL.URL_GAME_BANNER);
		
	}
	/**
	 * 游戏中心
	 * 
	 * @param params
	 * @param listener
	 */
	public void getGameIndex(GameParam params, VolleyListener listener) {
		post(ApiConfig.APIURL.URL_GAME_INDEX,
				ApiConfig.APIURL.URL_GAME_INDEX, params, listener);
	}
	/**
	 * 好友排名
	 * 
	 * @param params
	 * @param listener
	 */
	public void getGameFriendRankingList(GameParam params, VolleyListener listener) {
		post(ApiConfig.APIURL.URL_GAME_FRIEND_RANKING,
				ApiConfig.APIURL.URL_GAME_FRIEND_RANKING, params, listener);
		tags.add(ApiConfig.APIURL.URL_GAME_FRIEND_RANKING);
	}
	
	
	/**
	 * 个人最近所玩游戏列表
	 * 
	 * @param params
	 * @param listener
	 */
	public void getGameNearestList(GameParam params, VolleyListener listener) {
		post(ApiConfig.APIURL.URL_GAME_NEAREST_LIST,
				ApiConfig.APIURL.URL_GAME_NEAREST_LIST, params, listener);
		tags.add(ApiConfig.APIURL.URL_GAME_NEAREST_LIST);
	}
	
	/**
	 * 游戏详情
	 * 
	 * @param params
	 * @param listener
	 */
	public void getGameDetail(GameParam params, VolleyListener listener) {
		post(ApiConfig.APIURL.URL_GAME_DETAIL,
				ApiConfig.APIURL.URL_GAME_DETAIL, params, listener);
		tags.add(ApiConfig.APIURL.URL_GAME_DETAIL);
	}
	
	/**
	 * 提交游戏得分
	 * 
	 * @param params
	 * @param listener
	 */
	public void submitGameScore(GameParam params, VolleyListener listener) {
		postOnce(ApiConfig.APIURL.URL_GAME_SCORE,
				ApiConfig.APIURL.URL_GAME_SCORE, params, listener);
		tags.add(ApiConfig.APIURL.URL_GAME_SCORE);
	}
	
	
	/**
	 * 取消请求
	 * 
	 * @param context
	 */
	public void cancelAsyncHttp(Context context) {
		asyncHttpClient.cancelRequests(context, true);
	}
	
	public void cancelAll() {
		for (String tag : tags) {
			cancel(tag);
		}
	}

}
